<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    姓: <input type="text" v-model="firstName">
    名: <input type="text" v-model="lastName">
    <span>{{fullName}}</span>
    <button @click="changeName">改名卡</button>
  </div>
  <script src="../vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        firstName: '刘',
        lastName: '备',
      },
      methods: {
        changeName() {
          this.fullName = '你好'
        }
      },
      computed: {
        //简写 -> 获取,没有配置设置的逻辑
        // fullName() {
        //   return this.firstName + this.lastName
        // }
        //完整的写法 -> 获取 + 设置 也就是写成一个对象
        fullName: {

          get() {//获取值的
            return this.firstName + this.lastName
          },
          //当fullName计算属性 被修改赋值时 执行set
          set(value) {
            // 字符串的截取
            this.firstName = value.slice(0, 1)
            this.lastName = value.slice(1)
          }
        }
      }
    })
  </script>
</body>

</html>